package OOday01HomeWork;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class HomeWorkOODay01 {
    public static void main(String[] args) {
        //1.完成CommandBySwitch命令解析程序———————————练习switch
         System.out.println("请输入你的选择1.出去玩2.在家看电视3.玩手机4.吃饭");
        while (true){
            int comman = getScanner();
            if (verify(comman)!=-1){
                choose(comman);
                break;
            }else {
                System.out.println("请重新输入");
            }
        }
        //2.完成Guessing猜数字———————————————————练习while自造死循环
        int random = getRandom(1000,50);
        while (true){
            System.out.println("请输入数字开始猜测");
            int num = getScanner();
            if (num>random){
                System.out.println("大了");
            }else if (num<random){
                System.out.println("小了");
            }else {
                System.out.println("猜对了");
                break;
            }
        }
        //3.输出1到100的累加和———————————————————练习for循环
        int sum = 0;
        for (int i = 1; i < 101; i++) {
            sum+=i;
        }
        System.out.println(sum);
        //4.完成Addition随机加法运算符———————————————练习for循环
        Scanner sc = new Scanner(System.in);
        int sum1 = 0;//和
        int difference = 0;//差
        int minute = 0;//分数
        System.out.println("开始作答");
        for (int i = 1; i <= 10; i++) {
            int num1 = (int) (Math.random()*101);
            int num2 = (int) (Math.random()*101);
            int judge = (int) (Math.random()*2);
            if (judge==0) {
                sum1 = num1 + num2;
                System.out.println("（" + i + ")" + num1 + "+" + num2 + "=");
                int answer = sc.nextInt();
                if (answer == sum1) {
                    System.out.println("答对了");
                    minute += 10;
                } else {
                    System.out.println("答错了");
                }
            }else {
                difference = num1-num2;
                System.out.println("（" + i + ")" + num1 + "-" + num2 + "=");
                int answer2 = sc.nextInt();
                if (answer2 == difference) {
                    System.out.println("答对了");
                    minute += 10;
                } else {
                    System.out.println("答错了");
                }
            }
        }
        System.out.println(minute);
        //5.完成MuiltTable九九乘法表————————————————练习嵌套for循环
        for (int i = 0; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i+"*"+j+"="+i*j+"\t");
            }
            System.out.println("");
        }
        //6.完成MaxOfArray求数组元素最大值并放在最后一位—————练习数组、循环
        System.out.println("创建数组的长度");
        int[] array = intarray();//创建随机数组array
        pr(array);//输出array数组
        System.out.println(Arrays.toString(array));
        Arrays.sort(array);//数组从小到大顺序排序
        array = arrayAdd(array,1);//数组扩容一位
        array = arrayend(array,getmax(array));//最大值放在末位
        pr(array);//输出数组
        contrarypr(array);//反向输出数组
        max(array);//数组最大值
        min(array);//数组最小值
        //7.完成生成N位验证码———————————————————练习数组、循环和方法
         char[] vercode = getcharRandem(getRandem());
        String code = stringCharArray(vercode);
        System.out.println(code);
        //8.完成找到2到100之内的所有素数——————————————练习嵌套循环
         int num = getRandem(100,2);
        for (int i = 2; i < 100; i++) {
            onlyprime(i);

        }
        //9.完成飞机票打折—————————————————————练习分支和方法
        while (true) {
            System.out.println("请输入机票价格");
            int price = getScanner();
            System.out.println("请输入月份");
            int month = getScanner();
            System.out.println("请输入舱位1.头等舱2.商务舱3.经济舱");
            int type = getScanner();
            if (calAirPrice(price, month, type) < 0) {
                System.out.println("不对奥");
            } else {
                System.out.println("价格为" + calAirPrice(price, month, type));
                break;
            }
        }
        //10.完成评委打分:去掉最高分和最低分之后的平均分——————练习数组、循环和方法
         System.out.println("输入评委数量！！");
        int num3 = getScanner();
        System.out.println("一共有"+num3+"个评委，请依次输入评分");
        double[] data = inputData(num3);
        data = deleteMax(data);
        data = deleteMin(data);
        System.out.println(Arrays.toString(data));
        double mean = arrayMean(data);
        System.out.println("平均分为"+mean);
    }
    //输入
    public static int getScanner(){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        return a;
    }

    //验证合理
    public static int verify(int comman){
        if (comman<1||comman>4){
            return -1;
        }
        return comman;
    }

    //判断
    public static void choose(int comman){
        switch (comman){
            case 1:
                System.out.println("出去玩");
                break;
            case 2:
                System.out.println("在家看电视");
                break;
            case 3:
                System.out.println("玩手机");
                break;
            case 4:
                System.out.println("吃饭");
                break;

        }
    }

    //生成随机数
    public static int getRandom(int max,int min){
        Random random = new Random();
        int a = (random.nextInt(max-min))+min;
        return a;
    }

    //将传的值放于数组最后一位
    public static int[] arrayend(int[] array,int a){
        array[array.length-1]=a;//将值放于数组array最后一位
        return array;
    }

    //将数组扩容a位
    public static int[] arrayAdd(int[] array,int dilatation){
        array = Arrays.copyOf(array,array.length+dilatation);//将数组array扩容a位
        return array;
    }

    //创建随机数组
    public static int[] intarray(){
        int num = getScanner();
        int[] array = new int[num];
        for (int i = 0; i < array.length; i++) {
            array[i] = getRand();
//                System.out.println(i+1+"\t"+array[i]);
        }
        return array;
    }

    //1000以内随机数
    public static int getRand(){
        Random rd = new Random();
        int a = rd.nextInt(1001);
        return a;
    }

    //输出最大值
    public static int getmax(int array[]){
        int max=array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i]>max){
                max = array[i];
            }
        }
        return max;

    }

    //最大值
    public static void max(int array[]){
        int id = 1;
        int max=array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i]>max){
                max = array[i];
                id = i+1;
            }
//            System.out.println(id+"\t"+max);
        }
        System.out.println(id+"\t"+max);

    }

    //最小值
    public static void min(int array[]){
        int id = 1;
        int min=array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i]<min){
                min = array[i];
                id = i+1;
            }
//            System.out.println(id+"\t"+max);
        }
        System.out.println(id+"\t"+min);

    }

    //输出数组内容
    public static void pr(int array[]){
        for (int i = 0; i < array.length; i++) {
            System.out.println(i+1+"\t"+array[i]);
        }
    }

    //反向输出数组内容
    public static void contrarypr(int array[]){
        for (int i = array.length-1,j = 1; i >= 0; i--,j++) {
            System.out.println(j+"\t"+array[i]);
        }
    }

    //    生成max---min随机数
    public static int getRandem(int max,int min){
        Random random = new Random();
        int a;
        if (min!=0){
            a = random.nextInt(max)+min;
        }else {
            a = random.nextInt(max+1);
        }
        return a;
    }

    //    生成5----10随机数
    private static int getRandem(){
        Random random = new Random();
        int a = random.nextInt(6)+5;
        return a;
    }

    //    生成char数组
    private static char[] getcharRandem(int arraylong){
        Random random = new Random();
        char[] h = stringArray(arraylong);
        for (int i = 0; i < h.length; i++) {
            h[i] = randemChar();
        }
        return h;
    }

    //生成随机码
    private static char randemChar() {
        Random random = new Random();
        char a = 0;
        int e = random.nextInt(3);
        switch (e) {
            case 0:
                char b = (char) (random.nextInt(26) + 65);
                a = b;
                break;
            case 1:
                char c = (char) (random.nextInt(26) + 97);
                a = c;
                break;
            case 2:
                char d = (char) (random.nextInt(9) + 48);
                a = d;
                break;
        }
        return a;
    }

    //cha数组转为字符串
    public static String stringCharArray(char[] array){
        String a = "";
        for (int i = 0; i < array.length; i++) {
            a += array[i];
        }
        return a;
    }

    //创建随机数组
    public static char[] stringArray(int num){
        char[] array = new char[num];
        return array;
    }

    //只判断素数
    private static void onlyprime(int num){
        boolean flag = true;
        for (int i = 2; i <= num/2; i++) {
            if (num%i==0){
                flag = false;
                break;
            }
        }
        if (flag){
            System.out.print(num+"\t");
        }
    }

    //机票价格计算
    private static double calAirPrice(int price, int month,int Type){
        double a = 0.0;
        if (price<0||month<0||month>12||Type<0||Type>3){
            return -1;
        }else {
            switch (month) {
                case 3:
                case 4:
                case 5:
                case 6:
                case 2:
                    switch (Type) {
                        case 1:
                            a = price * 0.2;
                            break;
                        case 2:
                            a = price * 0.3;
                            break;
                        case 3:
                            a = price * 0.4;
                            break;
                    }
                case 1:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                case 12:
                    switch (Type) {
                        case 1:
                            a = price * 0.6;
                            break;
                        case 2:
                            a = price * 0.7;
                            break;
                        case 3:
                            a = price * 0.8;
                            break;
                    }
            }
        }
        return a;
    }

    //输入评委分数
    public static double[]inputData(int count){
        double[] data = new double[count];
        for (int i = 0; i < data.length; i++) {
            double a = getScanner();
            data[i] = a;
        }
        return data;
    }

    //去掉最高分
    public static double[] deleteMax(double[] array){
        double max = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j <= array.length-1; j++) {
                if (array[i]>array[j]){
                    max = array[j];
                    array[j] = array[i];
                    array[i] = max;
                }
            }
        }
        array = Arrays.copyOf(array,array.length-1);
        return array;
    }

    //去掉最低分
    public static double[] deleteMin(double[] array){
        double min = 0;
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j <= array.length-1; j++) {
                if (array[i]<array[j]){
                    min = array[j];
                    array[j] = array[i];
                    array[i] = min;
                }
            }
        }
        array = Arrays.copyOf(array,array.length-1);
        return array;
    }

    //输出数组总分
    public static double arraySum(double[] array){
        double sum = 0.0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return sum;
    }

    //输出数组平均分
    public static double arrayMean(double[] array){
        double mean = arraySum(array)/(array.length);
        return mean;
    }

}


